package com.soft.service.impl;

import com.soft.dao.IAccountDao;
import com.soft.domain.Account;
import com.soft.domain.TransferInfo;
import com.soft.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional//事务  类比较少的时候推荐注解配置事务  类比较多的时候推荐XML配置事务
public class IAccountServiceImpl implements IAccountService {

    @Autowired
    private IAccountDao accountDao;

    //查询所有的用户
    @Override
    public List<Account> findAll() {
        System.out.println("业务层-->查询所有的账户");

        List<Account> accounts = accountDao.findAll();
        return accounts;
    }

    //转账
    @Override
    public void transfer(TransferInfo transferInfo) {
        //分别更改两个账户的钱
        accountDao.updateMoney(transferInfo.getId1(),transferInfo.getMoney1());

        //有可能出现异常
//        int a = 1/0;

        accountDao.updateMoney(transferInfo.getId2(),transferInfo.getMoney2());
    }
}
